package com.renwei.yunlong.adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.renwei.yunlong.R;
import com.renwei.yunlong.bean.OwnerContentsBean;
import com.zyf.fwms.commonlibrary.base.baseadapter.BaseRecyclerViewAdapter;

/**
 * 选择所属服务目录 adapter
 * <p>
 * Created by Administrator on 2017/8/31.
 */

public class ServiceSelectAdapter extends BaseRecyclerViewAdapter<OwnerContentsBean.Rows> {

    private String directoryId;

    public ServiceSelectAdapter(Context context, String directoryId) {
        super(context);
        this.directoryId = directoryId;
    }

    @Override
    public OwnerContentsViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.item_select_belongs, null);
        return new OwnerContentsViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder rholder, final int position) {

        OwnerContentsViewHolder holder = (OwnerContentsViewHolder) rholder;
        final OwnerContentsBean.Rows rows = mList.get(position);
        if (!TextUtils.isEmpty(rows.getServicesDirectoryName())) {
            holder.tvTitle.setText(rows.getServicesDirectoryName());
        }
        if (!TextUtils.isEmpty(rows.getDetailName())) {
            holder.tvTitle.setText(rows.getDetailName());
        }
        if (!TextUtils.isEmpty(directoryId) && (directoryId.equals(rows.getId()+"")||directoryId.equals(rows.getDetailId()))) {
            //选中
            holder.rlRoot.setBackgroundColor(Color.parseColor("#F5F9FF"));
        } else {
            holder.rlRoot.setBackgroundColor(Color.WHITE);
        }
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mOnItemClickLitener.onItemClick(view, position);
            }
        });
    }

    class OwnerContentsViewHolder extends RecyclerView.ViewHolder {
        private View itemView;
        private TextView tvTitle;//标题
        private RelativeLayout rlRoot;

        public OwnerContentsViewHolder(View view) {
            super(view);
            itemView = view;
            tvTitle = itemView.findViewById(R.id.tv_title);
            rlRoot = itemView.findViewById(R.id.rl_root);
        }
    }

}
